﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using EZCRS.HCMS.Bll;

using EZCRS.HCMS.Entity;
using System.Collections.Generic;

namespace EZCRS.HCMS.Web.manage.AIR
{
    public partial class air_log_detail : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.QueryString["id"] != null)
                {
                    int iID = 0;
                    int.TryParse(Request.QueryString["id"], out iID);

                    BindData(iID);
                }
            }
        }


        private string GetWeekText(int i)
        {
            switch (i)
            {
                case 1:
                    return "周一";
                case 2:
                    return "周二";
                case 3:
                    return "周三";
                case 4:
                    return "周四";
                case 5:
                    return "周五";
                case 6:
                    return "周六";
                case 7:
                    return "周日";
            }

            return string.Empty;
        }

        private void BindData(int ID)
        {
            EZCRS.HCMS.Bll.AIR.AIR air = new EZCRS.HCMS.Bll.AIR.AIR();

            AIR_Log log = air.GetLogByID(ID);

            if (log != null)
            {
                lblStart.Text = log.StartDate.ToString("yyyy-MM-dd");
                lblEnd.Text = log.EndDate.ToString("yyyy-MM-dd");

                lblMax.Text = log.Max.ToString();
                lblMin.Text = log.Min.ToString();

                lblRoomAmount.Text = log.RoomInventory.ToString();
                lblCrateDate.Text = log.CrateDate.ToString();
                lblRoomState.Text = log.State;


                string [] str = log.WeekString.Split(',');
                string strWeek = "";

                for(int i = 0;i < 7;i++){

                    int iDay = i + 1;

                    if (str[i] == "1")
                        strWeek += GetWeekText(iDay) + ",";
                }

                lblWeek.Text = strWeek.TrimEnd(',');
                lblOper.Text = log.Operator;
                lblAdv.Text = log.AdvanceHour.ToString() + " H";
                
                //get detail

                List<AIR_LOG_CODE> codes = air.GetLogCodeListByLogID(log.ID);

                string strHtml = "";

                strHtml += "<table>";
                strHtml += "<tr class=\"tb_title\">";
                strHtml += "<td>房型代码</td>";
                strHtml += "<td>价格代码</td>";
                strHtml += "<td>单人价</td>";
                strHtml += "<td>双人价</td>";
                strHtml += "<td>三人价</td>";
                strHtml += "<td>四人价</td>";
                strHtml += "<td>含早</td>";
                strHtml += "</tr>";

                foreach (AIR_LOG_CODE code in codes)
                {
                    strHtml += "<tr>";
                    strHtml += "<td>" + code.RoomCode + "</td>";
                    strHtml += "<td>" + code.PlanCode + "</td>";
                    strHtml += "<td>" + log.Rate1.ToString("C") +"</td>";
                    strHtml += "<td>" + log.Rate2.ToString("C") + "</td>";
                    strHtml += "<td>" + log.Rate3.ToString("C") + "</td>";
                    strHtml += "<td>" + log.Rate4.ToString("C") + "</td>";

                    if(log.HasBreakfast)
                        strHtml += "<td>含早</td>";
                    else
                        strHtml += "<td>不含</td>";

                    strHtml += "</tr>";
                }

                strHtml += "</table>";

                litTable.Text = strHtml;

                //btnCreateMessage.Text = Resources.Site.CreateRateNotify;
            }

        }
    }
}
